import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gameplay_flutter/lib_runtime/extension/string_extension/string_text.dart';
import 'package:gameplay_flutter/m_room/constants/room_assets.dart';
import 'package:gameplay_flutter/m_room/room_dialog/room_gift.dart';
import 'package:gameplay_flutter/m_room/room_dialog/room_leave_the_mic.dart';
import 'package:gameplay_flutter/m_room/room_dialog/room_mic_requests.dart';
import 'package:gameplay_flutter/m_room/room_dialog/room_privacy.dart';
import 'package:gameplay_flutter/m_room/room_dialog/room_setting.dart';
import 'package:gameplay_flutter/m_room/room_dialog/room_user.dart';
import 'package:ones/ui.dart';

import '../room_controller/room_controller.dart';
import '../room_controller/room_stateless_controller_mixin.dart';
import '../room_dialog/room_edit.dart';
import '../room_dialog/room_pwd.dart';
import '../room_dialog/room_share.dart';

class RoomBottom extends StatelessWidget
    with StatelessControllerMixin<RoomController> {
  const RoomBottom({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 5.h, horizontal: 15.w),
      child: Row(children: [
        Image.asset(
          RoomAssets.roomBottomMicOn,
          width: 30.w,
          height: 30.h,
        ),
        SizedBox(
          width: 11.w,
        ),
        _buildInputText(context),
        SizedBox(
          width: 15.w,
        ),
        Image.asset(
          RoomAssets.roomBottomFunctionIcon,
          width: 32.w,
          height: 32.h,
        ).onClick(() {
          _showRoomSettingDialog(context);
        }),
        SizedBox(
          width: 13.w,
        ),
        Image.asset(
          RoomAssets.roomBottomApplyMic,
          width: 32.w,
          height: 32.h,
        ).onClick(() {
          _showMicRequestsDialog(context);
          // _showEditRoomDialog(context);
        }),
        SizedBox(
          width: 17.w,
        ),
        Image.asset(
          RoomAssets.roomBottomGitsIcon,
          width: 36.w,
          height: 36.h,
        ).onClick(() {
          _showGiftDialog(context);
        }),
        SizedBox(
          width: 18.w,
        ),
        Image.asset(
          RoomAssets.roomBottomGameIcon,
          width: 36.w,
          height: 36.h,
        ).onClick(() {
          // _showLeaveTheMic(context);
          // _showRoomPwdDialog(context);
          // _showShareRoomDialog(context);
          _showRoomPrivacyDialog(context);
        }),
      ]),
    );
  }

  Widget _buildInputText(BuildContext context) {
    return Expanded(
      child: Container(
        height: 30.h,
        padding: EdgeInsetsDirectional.only(start: 7.w),
        decoration: BoxDecoration(
          color: const Color(0x12FFFFFF),
          borderRadius: BorderRadius.circular(15.h),
        ),
        child: Row(
          children: [
            Image.asset(
              RoomAssets.roomBottomHi,
              width: 22.w,
              height: 22.h,
            ),
            SizedBox(
              width: 2.w,
            ),
            "Type...".text(
              fontSize: 12.sp,
              color: const Color(0xFFA5A1B9),
              weight: TextFontWeight.regular,
            )
          ],
        ),
      ).onClick(() {
        getRoomController(context).isInputVisible.value = true;
      }),
    );
  }

  void _showGiftDialog(BuildContext context) {
    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        barrierColor: Colors.transparent,
        constraints: BoxConstraints(
          maxHeight: 400.h,
        ),
        builder: (context) {
          return const RoomGift();
        });
  }

  void _showUserDialog(BuildContext context) {
    showModalBottomSheet(
      context: context,
      backgroundColor: Colors.transparent,
      constraints: BoxConstraints(maxHeight: 400.h),
      builder: (context) {
        return IntrinsicHeight(
          child: const RoomUser(),
        );
      },
    );
  }

  void _showRoomSettingDialog(BuildContext context) {
    showModalBottomSheet(
      context: context,
      backgroundColor: const Color(0xFF241235),
      barrierColor: Colors.transparent,
      constraints: BoxConstraints(maxHeight: 500.h),
      builder: (context) {
        return RoomSetting();
      },
    );
  }

  void _showLeaveTheMic(BuildContext context) {
    showModalBottomSheet(
      context: context,
      backgroundColor: Colors.white,
      barrierColor: const Color(0x8C181818),
      constraints: BoxConstraints(maxHeight: 300.h),
      builder: (context) {
        return RoomLeaveTheMic();
      },
    );
  }

  void _showMicRequestsDialog(BuildContext context) {
    showModalBottomSheet(
      context: context,
      backgroundColor: Colors.white,
      barrierColor: Colors.transparent,
      isScrollControlled: true,
      constraints: BoxConstraints(
        minHeight: MediaQuery.of(context).size.height * 0.7,
        maxHeight: MediaQuery.of(context).size.height * 0.7,
      ),
      builder: (BuildContext context) {
        return RoomMicRequests();
      },
    );
  }

  void _showEditRoomDialog(BuildContext context) {
    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        barrierColor: Colors.transparent,
        isScrollControlled: true,
        builder: (BuildContext context) {
          return RoomEdit();
        });
  }

  void _showShareRoomDialog(BuildContext context) {
    showModalBottomSheet(
        context: context,
        backgroundColor: const Color(0xFF241235),
        barrierColor: Colors.transparent,
        isScrollControlled: true,
        builder: (BuildContext context) {
          return RoomShare();
        });
  }

  void _showRoomPrivacyDialog(BuildContext context) {
    showModalBottomSheet(
        context: context,
        backgroundColor: const Color(0xFF241235),
        barrierColor: Colors.transparent,
        isScrollControlled: true,
        builder: (BuildContext context) {
          return RoomPrivacy();
        });
  }
  void _showRoomPwdDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return Dialog(
          insetPadding: EdgeInsets.symmetric(horizontal: 38.w), // 设置水平间距
          clipBehavior: Clip.hardEdge, // 防止内容溢出
          child: RoomPwd(), // RoomPwd 将根据内容自适应大小
        );
      },
    );
  }
}
